package com.akk.action;

import com.akk.business.AvsYbBankBusiness;
import com.akk.business.AvsYbCardBusiness;
import com.akk.business.AvsYbLoanBusiness;
import com.akk.module.avs.entity.AvsYbAppoCard;
import com.akk.module.avs.entity.AvsYbCardAccess;
import com.akk.module.avs.entity.AvsYbLoanAccess;
import com.akk.module.avs.model.request.AvsYbApplyLoanReq;
import com.akk.module.avs.model.request.AvsYbCardMatchRequest;
import com.akk.utils.RestResponse;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping(value = "/thmlfApi/avs/yb")
@Api(value = "御贝增值API")
public class AvsYbIncreAction {

    @Autowired
    private AvsYbLoanBusiness loanBusiness;

    @Autowired
    private AvsYbCardBusiness cardBusiness;

    @Autowired
    private AvsYbBankBusiness bankBusiness;

    @ApiOperation(value = "获取所有贷款类型",httpMethod = "GET",response = RestResponse.class)
    @ApiImplicitParam(paramType = "query",dataType = "String",name = "appId",value = "AppId",required = true)
    @GetMapping(value = "/loanTypes")
    public RestResponse loanTypes(String appId){
        return loanBusiness.loanTypes(appId);
    }

    @ApiOperation(value = "获取某一类型的贷款列表",httpMethod = "GET",response = RestResponse.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",dataType = "String",name = "appId",value = "AppId",required = true),
            @ApiImplicitParam(paramType = "query",dataType = "Long",name = "typeId",value = "类别Id",required = true)
    })
    @GetMapping(value = "/loanList")
    public RestResponse loanList(String appId,Long typeId){
        return loanBusiness.loanList(appId,typeId);
    }

    @ApiOperation(value = "获取贷款详情",httpMethod = "GET",response = RestResponse.class)
    @ApiImplicitParam(paramType = "query",dataType = "Long",name = "loanId",value = "贷款信息ID",required = true)
    @GetMapping(value = "/loanInfo/{loanId}")
    public RestResponse loanInfo(@PathVariable Long loanId){
        return loanBusiness.loanInfo(loanId);
    }

    @ApiOperation(value = "申请贷款产品",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/applyLoan")
    public RestResponse applyLoan(@RequestBody @Valid @ApiParam(name = "申请信息",value = "传入JSON",required = true) AvsYbApplyLoanReq req, BindingResult bindingResult){
        return loanBusiness.applyLoan(req, bindingResult);
    }

    @ApiOperation(value = "获取首页信用卡",httpMethod = "GET",response = RestResponse.class)
    @ApiImplicitParam(paramType = "query",dataType = "String",name = "appId",value = "AppId",required = true)
    @GetMapping(value = "/topCard")
    public RestResponse topCard(String appId){
        return cardBusiness.queryCardTop5(appId);
    }

    @ApiOperation(value = "获取全部信用卡",httpMethod = "GET",response = RestResponse.class)
    @ApiImplicitParam(paramType = "query",dataType = "String",name = "appId",value = "AppId",required = true)
    @GetMapping(value = "/allCard")
    public RestResponse allCard(String appId){
        return cardBusiness.cardAll(appId);
    }

    @ApiOperation(value = "预约办卡",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/appoCard")
    public RestResponse appoCard(@RequestBody @Valid @ApiParam(name = "申请信息",value = "传入JSON",required = true) AvsYbAppoCard req, BindingResult bindingResult){
        return cardBusiness.appoCard(req, bindingResult);
    }

    @ApiOperation(value = "办卡评估",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/accessCard")
    public RestResponse accessCard(@RequestBody @Valid @ApiParam(name = "评估信息",value = "传入JSON",required = true) AvsYbCardAccess req, BindingResult bindingResult){
        return cardBusiness.accessCard(req, bindingResult);
    }

    @ApiOperation(value = "贷款评估",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/accessLoan")
    public RestResponse accessLoan(@RequestBody @Valid AvsYbLoanAccess loanAccess,BindingResult bindingResult){
        return loanBusiness.loanAccess(loanAccess,bindingResult);
    }

    @ApiOperation(value = "获取信用卡攻略列表",httpMethod = "GET",response = RestResponse.class)
    @ApiImplicitParam(paramType = "query",dataType = "String",name = "appId",value = "AppId",required = true)
    @GetMapping(value = "/raiderCard")
    public RestResponse raiderCard(String appId){
        return cardBusiness.cardRaider(appId);
    }

    @ApiOperation(value = "根据选择标签推荐信用卡",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/matchCard")
    public RestResponse matchCard(@RequestBody @Valid @ApiParam(name = "评估信息",value = "传入JSON",required = true) AvsYbCardMatchRequest req, BindingResult bindingResult){
        return cardBusiness.match(req.getAppId(),req.getTags());
    }


    @GetMapping(value = "/info")
    public RestResponse info(String appId){
        return bankBusiness.info(appId);
    }

    @GetMapping(value = "/bankList")
    public RestResponse bankList(String appId){
        return bankBusiness.bankList(appId);
    }

    @GetMapping(value = "/queryBankList")
    public RestResponse queryBankList(String appId){
        return bankBusiness.queryBankList(appId);
    }

}
